package com.sjyy.common.sdk;

import java.io.IOException;
import java.util.HashMap;
import java.util.Properties;
import java.util.Set;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import com.cloopen.rest.sdk.CCPRestSDK;
import com.sjyy.common.util.PropertiesUtil;

public class SMSSDK {
	
	public static void sendConfirm(String createDate, String orderNumber, String telephone,String num,String price,String develieryDate){
		if(!PropertiesUtil.getProperty("sendSMS").equals("true")){
			return;
		}
		
		HashMap<String, Object> result = null;

		CCPRestSDK restAPI = new CCPRestSDK();
		//restAPI.init("sandboxapp.cloopen.com", "8883");// 测试   初始化服务器地址和端口
		restAPI.init("app.cloopen.com", "8883");// 生产   初始化服务器地址和端口
		
		restAPI.setAccount("aaf98f8946b91a580146ccab474e042a", "4076445919cb45a88f3b4f241dfa8020");// 初始化主帐号名称和主帐号令牌
		restAPI.setAppId("8a48b55146e1b04a0146f0827a6c03a0");// 初始化应用ID
		result = restAPI.sendTemplateSMS(telephone,"3360" ,new String[]{createDate,num,price,develieryDate});

		System.out.println("SDKTestGetSubAccounts result=" + result);
		
		if("000000".equals(result.get("statusCode"))){
			//正常返回输出data包体信息（map）
			HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
			Set<String> keySet = data.keySet();
			for(String key:keySet){
				Object object = data.get(key);
				System.out.println(key +" = "+object);
			}
		}else{
			//异常返回输出错误码和错误信息
			System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
		}
	}
	
	/**
	 * 发送缺货通知
	 * @param categoryName
	 * @param quantity
	 * @param telephone
	 */
	public static void sendOOS(String categoryName,String telephone){
		if(!PropertiesUtil.getProperty("sendSMS").equals("true")){
			return;
		}
		
		HashMap<String, Object> result = null;

		CCPRestSDK restAPI = new CCPRestSDK();
		//restAPI.init("sandboxapp.cloopen.com", "8883");// 测试   初始化服务器地址和端口
		restAPI.init("app.cloopen.com", "8883");// 生产   初始化服务器地址和端口
		
		restAPI.setAccount("aaf98f8946b91a580146ccab474e042a", "4076445919cb45a88f3b4f241dfa8020");// 初始化主帐号名称和主帐号令牌
		restAPI.setAppId("8a48b55146e1b04a0146f0827a6c03a0");// 初始化应用ID
		result = restAPI.sendTemplateSMS(telephone,"11588" ,new String[]{categoryName});

		System.out.println("SDKTestGetSubAccounts result=" + result);
		
		if("000000".equals(result.get("statusCode"))){
			//正常返回输出data包体信息（map）
			HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
			Set<String> keySet = data.keySet();
			for(String key:keySet){
				Object object = data.get(key);
				System.out.println(key +" = "+object);
			}
		}else{
			//异常返回输出错误码和错误信息
			System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
		}
	}
	
	/**
	 * 发送配送员信息
	 * @param deliveryName
	 * @param d_telephone
	 * @param telephone
	 */
	public static void sendDelivery(String deliveryName,String d_telephone,String telephone){
		if(!PropertiesUtil.getProperty("sendSMS").equals("true")){
			return;
		}
		
		HashMap<String, Object> result = null;

		CCPRestSDK restAPI = new CCPRestSDK();
		//restAPI.init("sandboxapp.cloopen.com", "8883");// 测试   初始化服务器地址和端口
		restAPI.init("app.cloopen.com", "8883");// 生产   初始化服务器地址和端口
		
		restAPI.setAccount("aaf98f8946b91a580146ccab474e042a", "4076445919cb45a88f3b4f241dfa8020");// 初始化主帐号名称和主帐号令牌
		restAPI.setAppId("8a48b55146e1b04a0146f0827a6c03a0");// 初始化应用ID
		result = restAPI.sendTemplateSMS(telephone,"9024" ,new String[]{deliveryName,d_telephone});

		System.out.println("SDKTestGetSubAccounts result=" + result);
		
		if("000000".equals(result.get("statusCode"))){
			//正常返回输出data包体信息（map）
			HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
			Set<String> keySet = data.keySet();
			for(String key:keySet){
				Object object = data.get(key);
				System.out.println(key +" = "+object);
			}
		}else{
			//异常返回输出错误码和错误信息
			System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
		}
	}
}
